import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

public class Temp1 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		File folder = new File("temp");
		File[] filesInDir = folder.listFiles();

		List<File> files = new ArrayList<File>();
		if (filesInDir != null) {
			int length = filesInDir.length;
			for (int i = 0; i < length; ++i) {
				File f = filesInDir[i];
				if (f.isFile()) {
					files.add(f);
				}
			}
		}
		Collections.shuffle(files);
		Collections.sort(files, new FileNameComparator());

		for (File file : files) {
			System.out.println(file.getName());
		}

	}
	
	private static Pattern taric2plusDailyFilePattern = Pattern.compile("[A-Z]{5}[0-9]{5}.*");
	static class FileNameComparator implements Comparator, Serializable {
        public int compare(Object o1, Object o2) {
            try {
                File f1 = (File) o1;
                File f2 = (File) o2;

                if (isMatching(f1.getName(), taric2plusDailyFilePattern) && isMatching(f2.getName(), taric2plusDailyFilePattern)) {
                    String file1_year = f1.getName().substring(5, 7);
                    String file1_seqNo = f1.getName().substring(7, 10);

                    String file2_year = f2.getName().substring(5, 7);
                    String file2_seqNo = f2.getName().substring(7, 10);

                    if (file1_year.compareTo(file2_year) < 0) {
                        return -1;
                    } else if (file1_year.compareTo(file2_year) > 0) {
                        return 1;
                    } else if (file1_year.equals(file2_year)) {
                        if (Integer.parseInt(file2_seqNo) < (Integer.parseInt(file1_seqNo))) {
                            return 1;
                        } else {
                            return -1;
                        }
                    }
                } else {
                    // Use old style compare
                    String file1_year = f1.getName().substring(3, 4);
                    String file1_seqNo = f1.getName().substring(4, 7);

                    String file2_year = f2.getName().substring(3, 4);
                    String file2_seqNo = f2.getName().substring(4, 7);

                    if (!file1_year.equals("0") && file2_year.equals("0")) {
                        return -1;
                    } else if (file1_year.equals("0") && !file2_year.equals("0")) {
                        return 1;
                    } else if (file1_year.equals(file2_year)) {
                        if (Integer.parseInt(file2_seqNo) < (Integer.parseInt(file1_seqNo))) {
                            return 1;
                        } else {
                            return -1;
                        }
                    }
                }


            } catch (ClassCastException ignored) {
            }

            return 0;
        }
    }
	public static boolean isMatching(String name, Pattern ptn) {
		return ptn.matcher(name).matches();
	}
}



